<?php
/**
 * Created by PhpStorm.
 * User: sunfan
 * Date: 2017/2/8
 * Time: 11:09
 * 首页
 */

namespace Clientapi\Controller;


class HomeController extends MapiBaseController
{

    public function index()
    {
        try{
            $db = M('Product');

            //新品热卖
            try{
                $news = $db->where(array('status'=>1,'is_home_new'=>1))->select();
            } catch (\Exception $e){
                $this->ApiReturn(10000,'网络错误');
            }

            for($i=0;$i<count($news);$i++){
                $new[$i]['pid'] = $news[$i]['id'];
                $new[$i]['title'] = $news[$i]['name'].$news[$i]['title'];
                $new[$i]['pic'] = 'http://'.$_SERVER['SERVER_NAME'].$news[$i]['image'];
                $new[$i]['price'] = $news[$i]['gprice'];
                $new[$i]['marketPrice'] = $news[$i]['market_price'];
            }
            $this->ApiReturn(0,'成功',$new);
        } catch (\Exception $e){
            $this->ApiReturn(10002,'系统错误');
        }
    }
}